home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBPCXL15.ARJ / DEMOS.ARJ / TESTPCX.C < prev    next >
Text File  |  1992-01-26  |  3KB  |  89 lines

  1. /*  testpcx.c  : test read/write pcx functions by writing an inverted  copy
  2.     of the input file */
  3.  
  4. #include <stdio.h>
  5. #include "pcxlib.h"
  6.  
  7. PCXF *pf1, *pf2, *pf3;
  8. char buffer[2000];
  9. #define FILLV   0x18
  10.  
  11.  
  12. void main(int argc, char *argv[])
  13. {
  14.     int i,ci, co;
  15.  
  16.     printf("PCXLIB v%s Testpcx.\n", PCXLIB_VERSION);
  17.  
  18.     if (argc < 2) {
  19.        printf("You must specify an input .pcx file.\n");
  20.        exit(1);
  21.     }
  22.  
  23.    /* Open debugging file */
  24.    #ifdef DEBUG
  25.    Start_pcxdebug("testpcx.dbg");            /* start debugging */
  26.    fprintf(pcxdebug,"\nMAIN: arguments are: 0=%s 1=%s\n", argv[0], argv[1]);
  27.    fprintf(pcxdebug,"   sizeof(PCXF)=%u %xh, sizeof(PCXH)=%u %xh\n",
  28.                     sizeof(PCXF), sizeof(PCXF), sizeof(PCXH), sizeof(PCXH));
  29.    #endif
  30.  
  31.    /* Open pcx file */
  32.    pf1=fopenPCXr(argv[1]); /* also reads header */
  33.    if (pf1->type != PCX256colors ) {
  34.       printf("Wrong pcx file, expected a 256 color file.\n");
  35.       exit(1);
  36.    }
  37.    printf("\nWe will be testing our ability to read and write pcx files by\n"
  38.             "reading the file you specify and producing two outputs:\n"
  39.             "   test1.pcx     : (hopefully) an exact copy of the input file\n"
  40.             "   test2.pcx     : a copy of the input file turned upside down\n"
  41.             "\n(hit any key to continue)\n\n");
  42.    getch();
  43.    pf2=fopenPCXw("test1.pcx",pf1->h,pf1->palette);
  44.    pf3=fopenPCXw("test2.pcx",pf1->h,pf1->palette);
  45.  
  46.    fseekPCX(pf1,0);
  47.    fseekPCX(pf2,0);
  48.    printf("Starting output to test1.pcx\n");
  49.    for (i=0; i<(pf1->l); i++) {
  50.        #ifdef DEBUG
  51.        fprintf(pcxdebug,"i=%i, ftell(pf1)=%li, ftell(pf2)=%li\n",
  52.                         i, ftell(pf1->fp), ftell(pf2->fp));
  53.        #endif
  54.        if ( ((i%16) == 0) && (i > 15))
  55.           *(pf1->marks + (i/16-1))=ftell(pf1->fp);
  56.        _read_pcx_line(pf1, buffer, 0, pf1->w-1);
  57.        _write_pcx_line(pf2, buffer, 0, pf2->w-1, FILLV);
  58.    }
  59.    fseekPCX(pf3,0);
  60.    _write_pcx_palette(pf2);
  61.    printf("Completed test1.pcx, starting test2.pcx (this will take a while).\n");
  62.  
  63.    if (pcxdebug) {
  64.       for (i=0; i<pf1->num_marks; i++) {
  65.           fprintf(pcxdebug,"mark[%i]=%li\n", i, *(pf1->marks+i));
  66.       }
  67.    }
  68.  
  69.    for (i=pf1->l-1; i> -1; i--) {
  70.        fseekPCX(pf1,i);
  71.        #ifdef DEBUG
  72.        fprintf(pcxdebug,"i=%i, ftell(pf1)=%li, ftell(pf3)=%li\n",
  73.                         i, ftell(pf1->fp), ftell(pf3->fp));
  74.        #endif
  75.        _read_pcx_line(pf1, buffer, 0, pf1->w-1);
  76.        _write_pcx_line(pf3, buffer, 0, pf3->w-1, FILLV);
  77.    }
  78.    printf("Completed test2.pcx.  Use showpcx to view the output files\n");
  79.  
  80.    _write_pcx_palette(pf3);
  81.    if (pcxdebug) fprintf(pcxdebug,"PCXerror=%i\n", PCXerror);
  82.    fclosePCX(pf1); fclosePCX(pf2); fclosePCX(pf3);
  83.    Close_pcxdebug();
  84.    exit(0);
  85. }
  86.  
  87.  
  88. 
  89.